package com.twu.biblioteca;

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: anubhav
 * Date: 1/7/14
 * Time: 4:15 AM
 * To change this template use File | Settings | File Templates.
 */
public class UserMenuComposer {

    private ArrayList<Book> list;
    private PrintStream out;
    private InputSeeker in;
    private ArrayList<Movie> movieList;

    public UserMenuComposer(ArrayList<Book> list, PrintStream out, InputSeeker in,ArrayList<Movie> movieList) {
        this.list = list;
        this.out = out;
        this.in = in;
        this.movieList = movieList;
    }

    public MenuGenerator getUserMenu(User user) {
        MenuGenerator menu = new MenuGenerator(out);
        Map<String, LibraryItem> availableBooks = prepareAvailableBooks(list);
        Map<String, IssuedBook> issuedBooks = new HashMap<String, IssuedBook>();
        Map<String, IssuedMovie> issuedMovies = new HashMap<String, IssuedMovie>();

        menu.addItem(new MenuOption(1, new BookListGenerator(list, out), "List all books"));
        menu.addItem(new MenuOption(2, new BookIssuer(prepareAvailableBooks(list), issuedBooks, out, new InputSeeker(), user.getLibraryNumber()), "Issue a book"));
        menu.addItem(new MenuOption(3, new BookReturn(availableBooks, issuedBooks, out, new InputSeeker()), "Return a book"));
        menu.addItem(new MenuOption(4, new ProfileViewer(user,out), "View Profile"));
        menu.addItem(new MenuOption(5,new MovieListGenerator(movieList,out),"List all Movies"));
        menu.addItem(new MenuOption(6,new MovieIssuer(prepareAvailableMovies(movieList),issuedMovies,out
                ,new InputSeeker(),user.getLibraryNumber()),"Issue a book"));
        return menu;


    }

    private Map<String, LibraryItem> prepareAvailableBooks(ArrayList<Book> list) {

        Map<String, LibraryItem> availableBooks = new HashMap<String, LibraryItem>();
        for (int i = 0; i < list.size(); i++) {
            availableBooks.put(list.get(i).getName(), list.get(i));
        }
        return availableBooks;
    }

    private Map<String, LibraryItem> prepareAvailableMovies(ArrayList<Movie> list) {

        Map<String, LibraryItem> availableBooks = new HashMap<String, LibraryItem>();
        for (int i = 0; i < list.size(); i++) {
            availableBooks.put(list.get(i).getName(), list.get(i));
        }
        return availableBooks;
    }


}
